// 滤镜的js
// 复古滤镜
function reminiscence_Filter(data1) {
		var data = data1
		for (i = 0; i < data.data.length - 4; i += 4) { //遍历各像素分量	
			var dr = .393 * data.data[i] + .769 * data.data[i + 1] + .189 * data.data[i + 2];
			var dg = .349 * data.data[i] + .686 * data.data[i + 1] + .168 * data.data[i + 2];
			var db = .272 * data.data[i] + .534 * data.data[i + 1] + .131 * data.data[i + 2];
			var scale = Math.random() * 0.5 + 0.5;
			data.data[i] = scale * dr + (1 - scale) * data.data[i];
			scale = Math.random() * 0.5 + 0.5;
			data.data[i + 1] = scale * dg + (1 - scale) * data.data[i + 1];
			scale = Math.random() * 0.5 + 0.5;
			data.data[i + 2] = scale * db + (1 - scale) * data.data[i + 2];
		}
		return data
}
//青色
function copy10(data2) { 
      var data = data2
      for (var i = 0; i < data.data.length; i += 4) { 
        //青色滤镜的算法：绿色通道值和蓝色通道值增加50（绿色+蓝色 = 青色） 
        var g = data.data[i+1] +50; 
        var b = data.data[i+2] +50 
        //注：当前值大于255时将其赋值255 
        data.data[i+1] = g > 255 ? 255 : g; 
        data.data[i+2] = b > 255 ? 255 : b; 
      } 
     return data
 }


onmessage = function(e){
	if(e.data.type=='复古'){
		postMessage(reminiscence_Filter(e.data.data)) 
	}else{
		postMessage(copy10(e.data.data)) 
	}
	
}